package boundary;

import controler.ConnectionManager;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Vector;
import controler.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class InserirPacotesServlet
 */
@WebServlet("/AutenticarServlet")
public class AutenticarServlet extends HttpServlet {
	HttpSession session;

	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public AutenticarServlet() {
        // TODO Auto-generated constructor stub
		CreateTables.Create("./bd");
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String usuario=request.getParameter("username");
		String senha=request.getParameter("senha");
		if(DataManager.login(usuario, senha)){
			session = request.getSession(true);
			session.setAttribute("username", usuario);
			response.sendRedirect("./index.jsp?lg=sc");
		}
		else{
			response.sendRedirect("./index.jsp?p=lg&&lg=n");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
